package org.liuqm.controller;


import org.liuqm.common.AjaxResult;
import org.liuqm.common.PageUtils;
import org.liuqm.common.RequestMapping;
import org.liuqm.entity.Auction;
import org.liuqm.service.IAuctionService;
import org.liuqm.service.impl.AuctionServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 所有拍卖相关接口
 */

@RequestMapping("/auction")
public class AuctionServlet {

    IAuctionService auctionService = new AuctionServiceImpl();

    @RequestMapping("/pageList")
    public AjaxResult getList(HttpServletRequest request, HttpServletResponse response) {
        AjaxResult ajaxResult = new AjaxResult();
        String name = request.getParameter("");
        String pageIndexStr = request.getParameter("pageIndex");
        String pageSizeStr = request.getParameter("pageSize");
        int pageBegin = pageIndexStr != null ? Integer.parseInt(pageIndexStr) : 1;
        int pageSize = pageSizeStr != null ? Integer.parseInt(pageSizeStr) : 2;
        Auction auction = new Auction();
        auction.setAuctionName(name);


        List<Auction> auctionList = auctionService.getPageList(auction, pageBegin, pageSize);
        int taltol = auctionService.getCount(auction);

        PageUtils<Auction> pageUtils = new PageUtils();
        pageUtils.setRecords(auctionList);
        pageUtils.setPageIndex(pageBegin);
        pageUtils.setPageSize(pageSize);
        pageUtils.setTotal(taltol);

        ajaxResult.setResult(pageUtils);
        return ajaxResult;
    }
}
